<?

/**
* Monthly update helpers
* 1. MST_SEQUENCE
* 
* @author   adesanto_asman@yahoo.com 
* @package  CMonthlyUpdate
*
*/

/**
* 
* @package CMonthlyUpdateVars
*
*/
class CMonthlyUpdateVars{
  
  /**
  * This var will be the reference (alias) of oracle handler
  *
  * @var string   $COracle
  *
  */
  var $COracle;
}

/**
* 
* @package CMonthlyUpdate
*
*/
class CMonthlyUpdate{
  
  /**
  * Auto contructor 
  * init the COracle
  *
  */
  function CMonthlyUpdate(&$COracle){
    
    $this->COracle = &$COracle;
  }
  
  /**
  * foreach sequence name 
  * DO : create new entry of sequence with current period
  *      and start with 1 as the sequence number
  * 
  * @param  void
  */
  function resetSequence($thisPeriode){
    
    $srcDbSequence  = "MST_SEQUENCE";
    
    $COracle = &$this->COracle;
    
    /**
    * check if this periode 
    * isExists
    * YES: Do nothing
    * NO : Process the reentry
    *
    */
    CGFetchers::fetchThisPeriodeSequence($COracle,
                                         $thisPeriode,
                                         $srcDbSequence,
                                         $isExists);
    
    if($isExists == false){
      
      /**
      * Fetch last periode of sequence
      *
      */
      CGFetchers::fetchLastPeriode($COracle,
                                   $srcDbSequence,
                                   $lastPeriode);
         
      CGFetchers::fetchSeqNameByDate($COracle,
                                     $lastPeriode,
                                     $srcDbSequence,
                                     $nSequence,
                                     $lstSeqName);
            
      for($iSeq = 0; $iSeq < $nSequence; $iSeq++){
        
        $seqPeriode = " TO_DATE('".$thisPeriode."' , 'mm-YYYY') ";
        
        $values = "  ".$seqPeriode." , ".         /* Sequence Periode */
                  " '".$lstSeqName[$iSeq]."', ".  /* Sequence Name    */
                  "      1  ";                    /* Sequence Number default is 1 */
                  
        CGHandlers::insSeqEntry($COracle,
                                $values,
                                $srcDbSequence);
      }
    }else{
      
      /* Do nothing */
    }
  }
}
?>